<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-9">
<title>Edit staff details</title>
<SCRIPT TYPE="text/javascript" src= "../../commonutils/util/util.js"> </SCRIPT>
</head>
<style type="text/css">
th {text-align: right}
</style>
<body>
<?php include 'top.html' ?>
<?php include '../../authorization_check.php'; ?>
<?php include '../../checkRootOnly.php'; ?>
<?php
  session_start(); 
?>


<?php
require_once '../../commonutils/db/DBConnectionManager.php';

if (isset($_POST['btnSubmit']))
{
	$username = $_POST['txtUsername'];
	$password = $_POST['txtPassword'];
	$password2 = $_POST['txtPassword2'];
	$userT = $_POST['txtUserType'];
	if($userT == "1") 
	{
		$userType=1;
	}
	else if($userT == "2")
	{
		$userType=2;
	}
	else if($userT == "3") 
	{
		$userType=3;
	}
	else if($userT == "4") 
	{
		$userType=4;
	}
	$firstname = $_POST['txtFirstname'];
	$lastname = $_POST['txtLastname'];
	$programC = $_POST['txtProgramCode'];
	if ($programC == "IS")
	{
		$programCode=9010;
	}
	else if ($programC == "COGS")
	{
		$programCode=9020;
	}
	else if ($programC == "MS") 
	{
		$programCode=9030;
	}
	else if ($programC == "ION") 
	{
		$programCode=9040;
	}
	else if ($programC == "SM") 
	{
		$programCode=9050;
	}
	else if ($programC == "MI") 
	{
		$programCode=9060;
	}
	else if ($programC == "WBLS") 
	{
		$programCode=9070;
	}
	
	if($password == $password2)
	{
		$sql = "select * from user where userName='".$username."' and password='".$password."'";
		//echo $sql;
	
	$r = DBConnectionManager::query($sql);
	if(mysql_num_rows($r) == 0)
	{
			$sqlquery = "insert into user(userName, password, userType, programCode, firstName, lastName) ".
						 "values ('".$username."','".$password."',".$userType.",".$programCode.",'".$firstname."','".$lastname."')";

			//echo $sqlquery;
			$result = DBConnectionManager::query($sqlquery);
			echo "<center><h4>User ".$username." has been created successfully</h4></center>"; 
		}
		else
		{
			echo "<center><h4>Sorry, user name and password entered exists in the system</h4></center>";
		}
	}
	else
	{
		echo "<center><h4>Retyped password does not match</h4></center>";
	}
	

}

?>
<center>  
<form method="POST" action="CreateUser.php">
	<table border="1" width="56%" id="table1">
		<tr>
			<td colspan="2" height="20"><center>
			<h1>Create User</h1>
			</center></td>
		</tr>
		<tr>
			<td width="112">User Name</td>
			<td width="162"><input type="text" name="txtUsername" size="40"></td>
		</tr>
		<tr>
			<td width="112">Password</td>
			<td width="162"><input type="password" name="txtPassword" size="40"></td>
		</tr>
		<tr>
			<td width="112">Retype Password</td>
			<td width="162"><input type="password" name="txtPassword2" size="40"></td>
		</tr>
		<tr>
			<td width="112">User Type</td>
			<td width="162">
				<select size="1" name="txtUserType">
					<option value="1">Program Coordinator</option>
					<option value="2">Vice Program Coordinator</option>
					<option value="3">Secretary</option>
					<option value="4">Student</option>
				</select>
			</td>
		</tr>
		<tr>
			<td width="112">First Name</td>
			<td width="162"><input type="text" name="txtFirstname" size="40"></td>
		</tr>
		<tr>
			<td width="112">Last Name</td>
			<td width="162"><input type="text" name="txtLastname" size="40"></td>
		</tr>
		<tr>
			<td width="112">Program Code</td>
			<td width="162">
				<select size="1" name="txtProgramCode">
					<option>IS</option>
					<option>COGS</option>
					<option>MS</option>
					<option>ION</option>
					<option>SM</option>
					<option>MI</option>
					<option>WBLS</option>
				</select>
			</td>
		</tr>
	</table>
	<input type="submit" value="Create" name="btnSubmit">&nbsp;&nbsp;
	<input type="reset" value="Clear" name="btnReset">&nbsp;
	<input type="reset" value="Cancel" name="btnCancel">
</form>
</center>



<br>
<hr color="blue">
<p>
  <a href="../../SecurityIndex.php">Back</a>
</p>


</body>
</html>





